﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QunYing.Web.market
{
    public partial class device : System.Web.UI.Page
    {
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Repeater rp = ((Repeater)Master.FindControl("NavRepeater"));
                rp.DataSource = NavData();
                rp.DataBind();
            }
        }
        /// <summary>
        /// 快捷导航数据
        /// </summary>
        private DataTable NavData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("name");
            dt.Columns.Add("url");
            dt.Rows.Add("设备配置", "");
            return dt;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlBind();
                BindInfo();
            }
        }

        /// <summary>
        /// 绑定下拉框
        /// </summary>
        private void ddlBind()
        {
            string userName = ((ArrayList)Session["userInfo"])[0].ToString();
            BLL.DeviceInfo info = new BLL.DeviceInfo();
            DataTable dt = info.QueryDevice(userName);
            ddlDevice.DataSource = dt;
            ddlDevice.DataTextField = "名称";
            ddlDevice.DataValueField = "ICSA编号";
            ddlDevice.DataBind();
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            BindInfo();
        }

        /// <summary>
        /// 绑定信息
        /// </summary>
        private void BindInfo()
        {
            BLL.ICSA_Device info = new BLL.ICSA_Device();
            Model.ICSA_Device model = info.GetModel(ddlDevice.SelectedValue);
            if (model == null)
            {
                clearText();
                return;
            }
            lblTime.Text = Convert.ToDateTime(model.配置更改时间).ToString("yyyy-MM-dd HH:mm");
            lblNo.Text = model.通信号码;
            lblICSA.Text = model.设备类型;
            //lblMoShi.Text = model.温度控制模式;
            lblWenDuChuanGan.Text = convertBool(model.温度传感器);
            lblWaterChuanGan.Text = convertBool(model.水位传感器);
            lblWaterXunHuan.Text = convertBool(model.水循环传感器);
            lblYangXunHuan.Text = convertBool(model.氧循环传感器);
            lblORP.Text = convertBool(model.ORP传感器);
            lblWaterPH.Text = convertBool(model.PH传感器);
            //lblGaiPH.Text = convertBool(model.钙反应PH传感器);
            lblMenXian.Text = model.温度门限值.ToString();
            lblWaterOPR.Text = model.ORP门限值.ToString();
            lblWaterPHValue.Text = model.PH门限值.ToString();
            //lblGaiPHValue.Text = model.钙反应器PH门限值.ToString();
            //lblStartTime1.Text = model.定时器1开启时间.ToString("HH:mm");
            //lblEndTime1.Text = model.定时器1关闭时间.ToString("HH:mm");
            //lblStartTime2.Text = model.定时器2开启时间.ToString("HH:mm");
            //lblEndTime2.Text = model.定时器2关闭时间.ToString("HH:mm");
            lblJianGe.Text = model.报警重复间隔时间.ToString()+"小时";
            lblShangBao.Text = convertBool(model.开启定时上报);
            //lblWarnNo.Text = model.报警接收手机号码;
            lblUpTime.Text = model.定时上报时间 == null ? "无" : model.定时上报时间.Value.ToString("HH:mm");
        }

        private string convertBool(bool b)
        {
            if (b)
            {
                return "有";
            }
            else
            {
                return "无";
            }
        }

        private void clearText()
        {
            lblTime.Text = "没有设备信息!";
            lblNo.Text = string.Empty;
            lblICSA.Text = string.Empty;
            //lblMoShi.Text = string.Empty;
            lblWenDuChuanGan.Text = string.Empty;
            lblWaterChuanGan.Text = string.Empty;
            lblWaterXunHuan.Text = string.Empty;
            lblYangXunHuan.Text = string.Empty;
            lblORP.Text = string.Empty;
            lblWaterPH.Text = string.Empty;
            //lblGaiPH.Text = string.Empty;
            lblMenXian.Text = string.Empty;
            lblWaterOPR.Text = string.Empty;
            lblWaterPHValue.Text = string.Empty;
            //lblGaiPHValue.Text = string.Empty;
            //lblStartTime1.Text = string.Empty;
            //lblEndTime1.Text = string.Empty;
            //lblStartTime2.Text = string.Empty;
            //lblEndTime2.Text = string.Empty;
            lblJianGe.Text = string.Empty;
            lblShangBao.Text = string.Empty;
            //lblWarnNo.Text = string.Empty;
            lblUpTime.Text = string.Empty;
        }
    }
}
